package lt.ntec.danblog.server.blog;

import lt.ntec.danblog.server.core.CommentService;
import lt.ntec.danblog.server.core.WebSiteErrorException;
import lt.ntec.danblog.server.core.model.Comment;
import lt.ntec.danblog.server.core.model.CommentDAO;
import lt.ntec.danblog.server.core.validator.ValidationException;

public class BlogCommentService implements CommentService {

    private CommentDAO dao;

    public BlogCommentService(CommentDAO commentDao) {
        this.dao = commentDao;
    }

    @Override
    public void removeComment(Long id) {
        dao.delete(id);
    }

    @Override
    public void updateComment(Long id, String content)
            throws WebSiteErrorException, ValidationException {

        Comment comment = dao.getById(id);
        comment.setContent(content);

        dao.save(comment);

    }

    @Override
    public void rateUpComment(Long id) throws WebSiteErrorException {
        Comment comment = dao.getById(id);
        comment.addVoteUp();
        dao.save(comment);

    }

    @Override
    public void rateDownComment(Long id) throws WebSiteErrorException {
        Comment comment = dao.getById(id);
        comment.addVoteDown();
        dao.save(comment);
    }
}
